(function($){

	function formResult(msg, state) {
        layer.closeAll();
        if(state == 0) {
            layer.alert(msg, {icon: 5});
        }else {
        	layer.alert(msg, {icon: 1},function(){
                parent.location.reload(true);
            });

        }
    }
    $(function(){
    	window.formResult = formResult;
        var $allMoney = parent.getTotalMoney();
        $('.totalMoney').text($allMoney);
        var date = $(window.parent.document).find("#ordertime").val();
        $("input[name='date']").val(date);
        $('input').on('change',function(){
            $(this).each(function(){
                var r = /^-?\d+$/ ;
                var s = /^[0-9]+\.[0-9]{0,2}$/;
                if($(this).val() !=''&&!r.test($(this).val())&&!s.test($(this).val())){
                    $(this).val("");
                }
            });
             var $dec1 = $('[name="balance_pay"]').val();
             var $dec2 = $('[name="give_balance_pay"]').val();
             var $dec3 = $('[name="cash_pay"]').val();
             var $dec4 = $('[name="union_pay"]').val();
             var $decAll = Number($dec1) + Number($dec2) + Number($dec3) + Number($dec4);

            $('.payMoney').text($decAll.toFixed(2))
            $('.repayment').text(($('.allMoney').text() - $decAll.toFixed(2)).toFixed(2))
        });

        $('input[type="reset"]').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })

    });
})(jQuery)

